<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Models\News\NewsClass;
use App\Models\Template;
use Encore\Admin\Form;
use Encore\Admin\Controllers\ModelForm;

class ColumnController extends Controller
{
    protected $name = '分类管理';
    use ModelForm;
    
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header($this->name);
            $content->description($this->name);


            $content->body(NewsClass::tree(function ($tree) {
                $tree->tools(function($tool){
                    $tool->add('<a class="btn btn-info btn-sm" onclick="build_common(\'NewsClass\', 0)">生成所有</a>');
                });

            }));
        });
    }
    
    /**
     * Edit interface.
     *
     * @param $id
     *
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header($this->name);
            $content->description('编辑');

            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {

            $content->header($this->name);
            $content->description('创建');

            $content->body($this->form());
        });
    }
    
    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        
        
        return Admin::form(NewsClass::class, function (Form $form) {
            
            $form->number('id', 'ID')->attribute('disabled', false);
            $form->text('name', '分类名称')->rules('required');
            $form->text('alias', '别名')->rules('required|unique:news_classes|max:30')->help('英文名称，用于生成静态目录');
            $form->number('listorder', '排序');
            $form->select('parent_id', '父栏目')->options(NewsClass::selectOptions())->rules('required');
            $form->select('index_temp_id', '封面模板')->options(Template::selectOptions(2));
            $form->select('cont_temp_id', '内容模板')->options(Template::selectOptions(3));
            
            
            $form->text('seo_title', 'SEO标题');
            $form->text('seo_keywords', 'SEO关键词');
            $form->text('seo_description', 'SEO描述');
            // $form->editor('contentccc', '描述');//->rules('required')
            // $form->editor('content', '内容')->help('如果是单页内容则填写，比如关于我们，联系我们');
            
            
            
        });
    }
}
